<style lang="less">
@import '../../../assets/style/yhqx_list.less';
</style>

<template>
	<mxq-router-layout>
		<div class="qxyh_list quexian_list">
			<Head slot="header" @headerClick="headerClick($event)">
				<div slot="headerTitle">
					<span>缺陷查看</span>
				</div>
				<div slot="headerRight" v-show="showHide">
					<span  @click.stop="headerClickHome" v-if="this.$route.query.towerStatus==0 ||this.$route.query.towerStatus==2"><i class="iconfont icon-shouye"/></span>
					<span v-else>新增</span>
				</div>
				<div slot="headerRight" v-show="isHome" @click.stop="headerClickHome">
					<i class="iconfont icon-shouye"/>
					<!-- <van-icon class="home" name="home"/> -->
				</div>
			</Head>

			<!--有数据时-->
			<GanTaList
				style="padding-bottom:75px;"
				v-if="qxLists && qxLists.length >= 0"
				:gantaList="qxLists"
				:picUrlLeft="picUrlLeft"
				@clickList="clickList($event)"
			>
				<template slot="titles" slot-scope="item">
					<span class="iconBox">
						<img
							:src="picUrlRight"
							alt=""
							class="arrow"
						>
					</span>
				</template>
			</GanTaList>

			<!--无数据时-->
			<div v-if="qxLists  && qxLists.length == 0" class="cont_box">
				<img class="pic_zanwu" src="../../../assets/img/changguixunshi/icon_zanwu.png" alt="">
				<p class="text_zanwu">暂无历史缺陷哦！！！</p>
			</div>
			<span  v-if="this.$route.query.towerStatus==0 || this.$route.query.towerStatus==2"></span>
			<van-tabbar v-else>
				<span  v-if="this.$route.query.towerStatus==2"></span>
				<van-button v-else size="large" type="primary" class="btn_list_sure" @click="confirm">确定</van-button>
			</van-tabbar>
		</div>
	</mxq-router-layout>
</template>

<script>
import Head from '@/components/head';
import GanTaList from '../../../components/ganta-list';
import IconTB from '../../../assets/img/changguixunshi/icon_ywc.png';
import IconJT from '../../../assets/img/changguixunshi/icon_jt.png';
import { callData } from '../../../axios/axios';
import {
	Cell,
	CellGroup,
	Button,
	Icon,
	Tabbar,
	TabbarItem,
	Toast
} from 'vant';

export default {
    name: 'quexianList',
    components: {
		Head,
		GanTaList,
		[Button.name]: Button,
		[Icon.name]: Icon,
		[Tabbar.name]: Tabbar,
		[TabbarItem.name]: TabbarItem
	},
	data() {
		return {
			showHide: true,			//隐藏"新增"
			isHome: false,
			qxLists:[],				//缺陷列表数据
			picUrlLeft: IconTB,		//列表左侧图标
			picUrlRight: IconJT,	//列表右侧小图标
			isShow: true, 			//是否显示确定按钮
			params: this.$route.query//获取地址栏参数
		}
	},
	mounted(){
		if(this.params.flag==true){
			Toast('你已经核查过了');
		}
		this.getListData()
		this.showHideFn()
	},
	methods: {
		// 头部两侧按钮点击事件
		headerClick(e){
			let query = {}
			this.$router.push({
				name:'tsxs_quexianXinzheng',
				query : {
					childNodeId: this.$route.query.childNodeId,
					name: this.$route.query.name,
					defectType: this.$route.query.defectType,
					towerId:this.$route.query.towerId,
					punchtype:this.$route.query.punchtype,
					lineId:this.$route.query.lineId,
					lineName:this.$route.query.lineName,
					towerName:this.$route.query.towerName,
					taskId :this.$route.query.taskId,
					lineTowerId :this.$route.query.lineTowerId,
					towerTaskId:this.$route.query.towerTaskId,
					index: this.$route.query.index
				}
			})
		},
		headerClickHome(){
			this.$router.push({name:"index"})
		},
		// 任务状态已完成隐藏可操作按钮
		showHideFn(){
			if(this.params.towerStatus==2) {
				this.showHide = false;
				this.isHome = true;
			}
		},
    	// 缺陷列表点击事件
		clickList(e){
			this.$router.push({
				path:'tsxs_quexianDetail',
				query: {
					name: this.$route.query.name,
					reviewType: e.data.REVIEW_TYPE,
					defectId: e.data.DEFECTID,
					towerId: this.$route.query.towerId,
					towerTaskId: this.$route.query.towerTaskId,
					lineName:this.$route.query.lineName,
					towerName:this.$route.query.towerName,
                    taskId: this.$route.query.taskId,
                    defectType: this.$route.query.defectType,
                    lineTowerId: this.$route.query.lineTowerId,
                    lineId: this.$route.query.lineId,
                    jdUserId: this.$route.query.jdUserId,
                    phoType: this.$route.query.phoType,
                    status: this.$route.query.phoType,
                    towerStatus: this.$route.query.towerStatus,
					needMeasure: this.$route.query.needMeasure,
					index: this.$route.query.index
				}
			})
		},
		// 确认点击事件
		confirm(){
			var params = {};
			params.towerTaskId = this.$route.query.towerTaskId,		//杆塔任务ID
			params.taskType = this.$route.query.index,              //任务类型: 0常规巡视 1特殊巡视 2保电值守 3线路检修
			params.towerId = this.$route.query.towerId,				//物理杆塔ID
			params.defectType = this.$route.query.defectType;		//缺陷类型
			callData('/accountServer/CmCheckDefect/addCmCheckDefect', 'post', params).then(res => {
				if(res.success){
					Toast(res.data)
					this.$router.go(-1)
					eventbus.$emit('scrollBottom',1)
				}
				else {
					Toast(res.data)
					// this.$router.go(-1)
				}
			})
		},
		getListData(){
			var params = {};
            params.towerId = this.$route.query.towerId;
            params.towerTaskId = this.$route.query.towerTaskId;
            params.taskId = this.$route.query.taskId;
			params.defectType = this.$route.query.defectType;
			console.log('params',params);
			callData('/accountServer/CmDefect/findTowerCmDefect', 'get', params).then(res => {
				var qxListData = res.data;
				qxListData.forEach((item,index) => {
					item.textName=item.DEFECT_CHARACTERIZATION;
					// 状态判断
					if (item.REVIEW_TYPE == "0") {
						item.statusName = '复核';
						item.cname = "btn_status";
					}
					else if (item.REVIEW_TYPE == "1") {
						item.statusName = '消缺';
						item.cname = "btn_status1";
					}
					else if (item.REVIEW_TYPE == "2") {
						item.statusName = '新增';
						item.cname = "btn_status3";
					}
					else if (item.REVIEW_TYPE == "3") {
						item.statusName = '待处理';
						item.cname = "btn_status2";
					}
				});
				this.qxLists = qxListData
				// 如果缺陷为选中状态则隐藏确定按钮

				/* if(this.params.flag==true){
					this.isShow = false;
				}
				if(this.params.flag==false){
					this.isShow = true;
				} */
			})
		}
	}
}
</script>